home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 349 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.5 KB

  1. Path: solon.com!not-for-mail
  2. From: Jens M Andreasen <jens-and@dsv.su.se>
  3. Newsgroups: comp.std.c,comp.lang.c.moderated
  4. Subject: Re: Integral promotion.
  5. Date: 21 Feb 1996 17:55:06 -0600
  6. Organization: Digital Solutions
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4ggbcq$81c@solutions.solon.com>
  10. NNTP-Posting-Host: solutions.solon.com
  11.  
  12.  
  13.  
  14. On 21 Feb 1996, S. Lee wrote:
  15.  
  16. > >> The addition operator "+" converts your short operands to ints.
  17. > >
  18. > >No, just using their values does that ...
  19.  
  20. > Okay, I'm confused.  Let just say the above is true.  Then the expression
  21. > "x1 + x2" has type int because x1 and x2 were converted to int before
  22. > being passed to the + operator.
  23.  
  24. I admit that I am confused too. So in this case the compiler should issue a 
  25. warning for { short x = 0; x++; } since "x++" equals "x = x + 1" and both 
  26. "x" and "1" are promoted to integers, and there could therefore be a 
  27. potential loss of precision because "sizeof(int) > sizeof(short)", but no 
  28. precision could have been lost if int and short had been the same (small) 
  29. size ?? <phew>
  30.  
  31. This again implies that the ++ operator should be avoided on short 
  32. since it is destined to cause havoc and confusion ... Which in turn is 
  33. not the way C is written ... (Ehrm  :)
  34.  
  35. [testing] _I can't even cast my way out of this!?_ 
  36.   
  37. problem_with(short i){
  38.   assert(sizeof (int) > sizeof (short));
  39.   return i++;    /* Warning: Precision may be lost */
  40. }
  41.  
  42. I never saw this in any textbook :-) 
  43.  
  44. // Jens M Andreasen
  45.